<template>
	<div class="income-submit-confirm" v-show="false" v-if="confirmData">
		<p class="title">报名信息确认</p>
		<ul class="submit-table">
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">姓名</span>
					<span class="submit-table-right">{{confirmData.name}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">支付方式</span>
					<span class="submit-table-right">{{confirmData.paymentMethod=="1"?"支付宝":confirmData.paymentMethod=="2"?"微信":confirmData.paymentMethod=="3"?"现金":confirmData.paymentMethod=="4"?"刷卡":"未知"}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">性别</span>
					<span class="submit-table-right">{{$dicCache.getNameByMarkAndVal('XBDM', confirmData.sex)}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">总金额</span>
					<span class="submit-table-right totalNum">￥{{confirmData.totalAmount}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">证件号码</span>
					<span class="submit-table-right">{{confirmData.cardnum}}</span>
				</div>
			</li>
			<li class="submit-table-item" v-if="confirmData.isDiscount && Number(confirmData.discountAmount) > 0">
				<div class="submit-table-cont">
					<span class="submit-table-left">优惠金额</span>
					<span class="submit-table-right">￥{{confirmData.discountAmount}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">培训车型</span>
					<span class="submit-table-right">{{confirmData.traintype}}</span>
				</div>
			</li>
			<li class="submit-table-item" v-if="confirmData.isDiscount && Number(confirmData.discountAmount) > 0">
				<div class="submit-table-cont">
					<span class="submit-table-left">优惠备注</span>
					<span class="submit-table-right">{{confirmData.discountRemark}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">手机号码</span>
					<span class="submit-table-right">{{confirmData.phone}}</span>
				</div>
			</li>
			<li class="submit-table-item" v-if="confirmData.payType != 2">
				<div class="submit-table-cont">
					<span class="submit-table-left">实收金额</span>
					<span class="submit-table-right">￥{{Number(confirmData.totalAmount) - Number(confirmData.discountAmount||0)}}</span>
				</div>
			</li>
			<li class="submit-table-item" v-if="confirmData.payType == 2">
				<div class="submit-table-cont">
					<span class="submit-table-left">本期金额</span>
					<span class="submit-table-right">￥{{Number(confirmData.amount||0)}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">付费类型</span>
					<span class="submit-table-right">{{confirmData.payType=="1"?"全额付款":confirmData.payType=="2"?"分期付款[共" + confirmData.instalment +"期]":confirmData.payType=="3"?"先学后付":"包库学员"}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">{{confirmData.payType=="4"?"包库教练员":"招生业务员"}}</span>
					<span class="submit-table-right">{{confirmData.clerkName}}</span>
				</div>
			</li>
			<li class="submit-table-item">
				<div class="submit-table-cont">
					<span class="submit-table-left">备注</span>
					<span class="submit-table-right">{{confirmData.remark}}</span>
				</div>
			</li>
		</ul>
		<el-col :span="24" style="margin-top:14px" class="btn-group">
			<el-button type="danger" round class="add-btn" @click="submit">提 交</el-button>
			<el-button type="danger" round class="select-btn" @click="close">取 消</el-button>
		</el-col>
	</div>
</template>
<script>
	export default {
		name: "",
		props: {
			value: {
				type: Boolean,
				default: false
			},
			confirmData: {
				type: Object
			}
		},
		data() {
			return {
				visible: this.value,
				layIndex: null
			};
		},
		methods: {
			submit() {
//				console.info(JSON.parse(JSON.stringify(this.confirmData)));

				// 全额付款
				if(this.confirmData.payType == '1') {
					this.commitData({
						stuBh: this.confirmData.studentId,
						stuName: this.confirmData.name,
						idCard: this.confirmData.cardnum,
						traintype: this.confirmData.traintype,
						payType: this.confirmData.payType,
						paymentMethod: this.confirmData.paymentMethod,
						remark: this.confirmData.remark,
						totalAmount: this.confirmData.totalAmount,
						discountAmount: this.confirmData.discountAmount,
						discountRemark: this.confirmData.discountRemark,
						clerkBh: this.confirmData.clerkBh
					});
				}
				// 分期付款
				if(this.confirmData.payType == '2') {
					if(this.confirmData.instalmentNo == 1) {
						this.commitData({
							stuBh: this.confirmData.studentId,
							stuName: this.confirmData.name,
							idCard: this.confirmData.cardnum,
							traintype: this.confirmData.traintype,
							payType: this.confirmData.payType,
							paymentMethod: this.confirmData.paymentMethod,
							remark: this.confirmData.remark,
							totalAmount: this.confirmData.totalAmount,
							instalment: this.confirmData.instalment,
							amount: this.confirmData.amount,
							subject: this.confirmData.subject,
							clerkBh: this.confirmData.clerkBh,
							instalmentNo: 1
						});
					} else {
						this.commitData({
							payBh: this.confirmData.pbh,
							stuName: this.confirmData.name,
							idCard: this.confirmData.cardnum,
							traintype: this.confirmData.traintype,
							payType: this.confirmData.payType,
							paymentMethod: this.confirmData.paymentMethod,
							remark: this.confirmData.remark,
							totalAmount: this.confirmData.totalAmount,
							instalmentNo: this.confirmData.instalmentNo,
							companyName: this.confirmData.companyName,
							amount: this.confirmData.amount,
							subject: this.confirmData.subject.join(),
							clerkBh: this.confirmData.clerkBh
						}, 'iem/instalment');
					}
				}
				// 先学后付
				if(this.confirmData.payType == '3') {

				}
				// 包库学员
				if(this.confirmData.payType == '4') {
					this.commitData({
						stuBh: this.confirmData.studentId,
						stuName: this.confirmData.name,
						idCard: this.confirmData.cardnum,
						traintype: this.confirmData.traintype,
						payType: this.confirmData.payType,
						paymentMethod: this.confirmData.paymentMethod,
						remark: this.confirmData.remark,
						totalAmount: this.confirmData.totalAmount,
						clerkBh: this.confirmData.clerkBh
					});
				}

			},
			commitData(data, url) {
				this.$http.post(url || 'iem/stupayment', data, (d) => {
					if(d.status == '1') {
						layer.msg(d.msg, {
							time: 1000,
							shade: 0.3
						}, function() {
							layer.confirm('是否打印小票？', {
								title: '打印确认',
								btn: ['是', '否']
							}, function(index, layero) {
								window.open(process.env.API_BASH_URL + "print/bmf/" + d.data.obj, "_blank", "directories=0,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0");
								top.location.reload();
							}, function() {
								top.location.reload();
							});
						});
					} else {
						layer.msg(d.msg, {
							shift: 6
						});
					}
				});
			},
			close() {
				this.visible = false;
				this.$emit('input', false);
			}
		},
		watch: {
			value(val) {
				this.visible = val;
			},
			visible(val) {
				if(val === false) {
					layer.close(this.layIndex);
				} else {
					this.$nextTick(() => {
						let that = this;
						this.layIndex = layer.open({
							type: 1,
							shadeClose: true,
							title: "",
							skin: "layui-layer-rim", //加上边框
							area: ["60%", "500px"], //宽高
							content: $(this.$el),
							end: function() {
								that.close();
							}
						});
					});
				}
			}
		}
	};
</script>

<style scoped>
	.add-btn {
		height: 40px;
		padding: 0 33px;
		float: right;
		background: url("/static/img/nav-bg.png");
		background-size: 100% 100%;
		border: 0;
	}
	
	.select-btn {
		height: 40px;
		padding: 0 33px;
		margin-right: 20px;
		float: right;
		background: url("/static/img/hui-btnBG.png");
		background-size: 100% 100%;
		border: 0;
		color: #000;
	}
	
	.totalNum {
		color: #ff3333;
	}
	
	.title {
		width: 100%;
		float: left;
		padding: 18px 0;
		color: #575757;
		font-size: 22px;
	}
	
	.submit-table {
		width: 100%;
		float: left;
		border: 1px solid #d9d9d9;
		background: #f1f1f1;
		border-radius: 3px;
	}
	
	.submit-table-item {
		width: 50%;
		float: left;
		padding: 18px 0;
		border-bottom: 1px solid #d9d9d9;
	}
	
	.submit-table-item:last-child {
		border: 0;
	}
	
	.submit-table-cont {
		width: 100%;
		float: left;
	}
	
	.submit-table-left {
		width: 20%;
		float: left;
		text-align: right;
		padding-right: 5%;
		color: #9d9d9d;
	}
	
	.submit-table-right {
		width: 75%;
		float: left;
		color: #575757;
	}
</style>